package com.yxy.controller.admin;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.pojo.dto.SightsDTO;
import com.yxy.pojo.dto.SightsPageQueryDTO;
import com.yxy.service.SightsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminSightsController")
@RequestMapping(RequestMapperConstant.ADMIN_REQUEST_MAPPER + "sights")
@Slf4j
public class SightsController {

    @Autowired
    private SightsService sightsService;

    /**
     * 分页查询
     * @param sightsPageQueryDTO
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult> pageQuery(SightsPageQueryDTO sightsPageQueryDTO){
        log.info("分页查询景点信息：{}", sightsPageQueryDTO);
        PageResult result = sightsService.pageQuery(sightsPageQueryDTO);
        return Result.success("", result);
    }

    /**
     * 添加景点
     * @param sightsDTO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody SightsDTO sightsDTO){
        log.info("添加景点信息：{}", sightsDTO);
        sightsService.add(sightsDTO);
        return Result.success("新增成功");
    }

    /**
     * 修改景点状态
     * @return
     */
    @PutMapping("/update/{id}/{status}")
    public Result updateStatus(@PathVariable int id, @PathVariable int status){
        log.info("修改景点状态：{}, {}", id, status);
        sightsService.updateStatus(id, status);
        return Result.success("", null);
    }

    /**
     * 批量删除景点
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam List<Integer> ids){
        log.info("批量删除景点：{}", ids);
        sightsService.batchDelete(ids);
        return Result.success("删除成功");
    }

    /**
     * 修改景点信息
     * @param sightsDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody SightsDTO sightsDTO){
        log.info("修改景点信息：{}", sightsDTO);
        sightsService.update(sightsDTO);
        return Result.success("修改成功");
    }
}
